package cn.pconline.autoclub.web;

import cn.pconline.autoclub.entity.BbsActionLog;
import cn.pconline.autoclub.service.BbsActionLogService;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 论坛同步日志
 */
@Controller
public class BbsSyncController {

    @Autowired
    private BbsActionLogService bbsActionLogService;
    
    protected static final Logger log = LoggerFactory.getLogger(BbsSyncController.class);

    @RequestMapping(value = "/bbs/receive")
    @ResponseBody
    public String receive(HttpServletRequest request) throws UnsupportedEncodingException {
        request.setCharacterEncoding("gbk");
        long logId = NumberUtils.toLong(request.getParameter("logId"));
        long topicId = NumberUtils.toLong(request.getParameter("topicId"));
        long forumId = NumberUtils.toLong(request.getParameter("forumId"));
        long userId = NumberUtils.toLong(request.getParameter("userId"));
        long createAt = NumberUtils.toLong(request.getParameter("createAt"));
        int typeId = NumberUtils.toInt(request.getParameter("typeId"));
        String content = request.getParameter("content");
        BbsActionLog actionLog = new BbsActionLog();
        actionLog.setLogId(logId);
        actionLog.setTopicId(topicId);
        actionLog.setForumId(forumId);
        actionLog.setUserId(userId);
        actionLog.setContent(content);
        actionLog.setTypeId(typeId);
        actionLog.setCreateAt(new Date(createAt));
        try {
            bbsActionLogService.service(actionLog, typeId);
        } catch (Exception e) {
            log.error("receive fail!",e);
        }
        return "";
    }
}
